<script setup lang="ts">
import DoctorCard from './DoctorCard.vue'
import { useWindowSize } from '@vueuse/core'
const { width } = useWindowSize()
import { ref, onMounted } from 'vue'
import emptyImage from '@/assets/empty.png'
// 原生写法
// const windowWidth = ref(window.innerWidth)
// // 监听窗口变化
// onMounted(() => {
//   window.addEventListener('resize', () => {
//     windowWidth.value = window.innerWidth
//   })
// })

import { getRecommendDoctorService } from '@/api/consult'
import type { DoctorPage, DoctorList } from '@/types/consult'
const doctorList = ref<DoctorList>()
const params = ref({
  current: 1,
  pageSize: 5,
})
const getRecommendDoctor = async () => {
  const { pageTotal, rows } = await getRecommendDoctorService(params.value)
  doctorList.value = rows
}
onMounted(() => {
  getRecommendDoctor()
})
</script>

<template>
  <div class="follow-doctor">
    <div className="head">
      <p>推荐关注</p>
      <a href="javascript:;"> 查看更多<i class="van-icon van-icon-arrow" /></a>
    </div>
    <div class="body">
      <template v-if="doctorList?.length">
        <van-swipe :width="(150 / 350) * width" :show-indicators="false" :loop="false">
          <van-swipe-item v-for="item in doctorList" :key="item.id">
            <doctor-card :item="item" />
          </van-swipe-item>
        </van-swipe>
      </template>
      <template v-else>
        <van-empty :image="emptyImage" imageSize="80" description="暂无推荐关注" />
      </template>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.follow-doctor {
  background-color: var(--cp-bg);
  // height: 250px;
  padding-bottom: 20px;
  .head {
    display: flex;
    justify-content: space-between;
    height: 45px;
    align-items: center;
    padding: 0 15px;
    font-size: 13px;
    > a {
      color: var(--cp-tip);
    }
  }
  .body {
    width: 100%;
    overflow: hidden;
    .van-empty {
      --van-empty-padding: 0;
    }
  }
}
</style>
